﻿
using UnityEngine; 


namespace XFGameFramework.Localization
{
    /// <summary>
    /// 本地化基类
    /// </summary>
    [DisallowMultipleComponent]
    public abstract class LocalizeBase : MonoBehaviour
    {
        #region 字段

        /// <summary>
        /// 语言配置ID(唯一标识)
        /// </summary>
        [SerializeField]
        [Header("语言配置ID(唯一标识)")]
        [Tooltip("语言配置ID(唯一标识)")]
        private int id;

        #endregion

        #region 属性

        /// <summary>
        /// 语言配置ID(唯一标识)
        /// </summary>
        public int ID
        {
            get
            {
                return id;
            }
            set
            {
                if (id == value) return;
                id = value;
                OnLanguageValueChange();
            }
        }

        #endregion

        #region 生命周期 
        private void OnEnable()
        {
            EventManager.AddEvent(LocalizationEventConst.ON_LANGUAGE_VALUE_CHANGE, OnLanguageValueChange);
            OnLanguageValueChange();
        }

        private void OnDisable()
        {
            EventManager.RemoveEvent(LocalizationEventConst.ON_LANGUAGE_VALUE_CHANGE, OnLanguageValueChange);
        }
        #endregion


        #region 方法

        /// <summary>
        /// 语言id改变时触发
        /// </summary>
        protected virtual void OnLanguageValueChange()
        { 
        }
        #endregion

    }

}

